﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;

public partial class mendoctor_CFStart : System.Web.UI.Page
{
    public int stuID;
    public OleDbConnection mmmmm;
    public static readonly string sssss = System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        mmmmm = new OleDbConnection(sssss);
        mmmmm.Open();
        if (Session["UserName"] == null && Session["UserNo"] == null)
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>" +
                "alert('登录超时（或未登录），请您重新登录！'); parent.location.href='../login.aspx'</script>", false);
        stuID = int.Parse(Request.QueryString["stuID"]);
        if (!IsPostBack)
            bind(stuID);
    }
    protected void ButtonOK_Click(object sender, EventArgs e)
    {
       
        string mystr1 = "update GH set ID_JZ='" + UserNo.Text.Trim() + "',Gtime='" + time.Text.Trim() + "',Name='" +
           name.Text.Trim() + "',Dsubject='" + ks.Text.Trim() + "',Dname='" + ys.Text.Trim() + "',Cname='" + xm.Text.Trim() + "',Csp='" + gg.Text.Trim() + "',Cun='" + dw.Text.Trim() + "',Mnum='" + sl.Text.Trim() + "',Znum='" + cs.Text.Trim() + "',NUM='" + zl.Text.Trim() + "' where ID=" + stuID + " ";
        OleDbCommand mycmd1 = new OleDbCommand(mystr1, mmmmm);
        mycmd1.ExecuteNonQuery();
        string mystr2 = "update PatCF set ID_JZ='" + UserNo.Text.Trim() + "',Gtime='" + time.Text.Trim() + "',Name='" +
          name.Text.Trim() + "',Dsubject='" + ks.Text.Trim() + "',Dname='" + ys.Text.Trim() + "',Cname='" + xm.Text.Trim() + "',Csp='" + gg.Text.Trim() + "',Cun='" + dw.Text.Trim() + "',Mnum='" + sl.Text.Trim() + "',Znum='" + cs.Text.Trim() + "',NUM='" + zl.Text.Trim() + "' where ID_JZ='" + UserNo.Text.Trim() + "' ";
        OleDbCommand mycmd2 = new OleDbCommand(mystr2, mmmmm);
        mycmd2.ExecuteNonQuery();
      
        Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('成功录入新的处方信息!');</script>", false);
    }
    protected void ButtonReset_Click(object sender, EventArgs e)
    {
        bind(stuID);
    }

    public void bind(int id)
    {
        string mysql = "select * from GH where ID=" + id + " ";
        OleDbCommand mycmd = new OleDbCommand(mysql, mmmmm);
        OleDbDataReader myReader = mycmd.ExecuteReader();
        if (myReader.Read())
        {
            UserNo.Text = myReader[1].ToString();
            time.Text = myReader[2].ToString();
            name.Text = myReader[3].ToString();
            ks.Text = myReader[4].ToString();
            ys.Text = myReader[5].ToString();
            xm.Text = myReader[6].ToString();
            gg.Text = myReader[7].ToString();
            dw.Text = myReader[8].ToString();
            sl.Text = myReader[9].ToString();
            cs.Text = myReader[10].ToString();
            ts.Text = myReader[11].ToString();
            zl.Text = myReader[12].ToString();
        }
        else
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('操作有误！'); location.href='CF.aspx'</script>", false);
    }
}